package com.CloudDream;

import com.CloudDream.Command.MoonCakeCommand;
import com.CloudDream.PlaceHolder.hook;
import com.CloudDream.Util.RecipeUtil;
import com.CloudDream.config.Config;
import com.handy.lib.InitApi;
import com.handy.lib.util.BaseUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabExecutor;
import org.bukkit.plugin.java.JavaPlugin;

public class MoonCake extends JavaPlugin {

    private final static String PACKAGE_NAME = "com.CloudDream.Command";
    private final static String LISTENER_PACKAGE_NAME = "com.CloudDream.Listener";
    public static MoonCake INSTANCE;
    public static String prefix;

    public static MoonCake getInstance() {
        return INSTANCE;
    }

    public void onEnable() {
        INSTANCE = this;
        prefix = BaseUtil.replaceChatColor(this.getConfig().getString("Message.prefix"));
        InitApi initapi = InitApi.getInstance(this);
        this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "欢迎使用MoonCake 版本1.1");
        this.getConfig().options().copyDefaults(true);
        this.saveConfig();
        this.saveDefaultConfig();
        this.getCommand("mooncake").setExecutor((CommandExecutor) new MoonCakeCommand());
        this.getCommand("mooncake").setTabCompleter((TabExecutor) new MoonCakeCommand());
        RecipeUtil.Ingredient();
        Config.loadData();

        initapi.initCommand(PACKAGE_NAME)
                .initSubCommand(PACKAGE_NAME)
                .initListener(LISTENER_PACKAGE_NAME);

        if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            (new hook(this)).register();
            this.getLogger().info("PAPI关联成功");
        } else {
            this.getLogger().info("PAPI关联失败！请检查PlaceHolderAPI是否已经安装");
        }
    }

    public void onDisable() {
        this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "感谢使用MoonCake 版本1.1");
    }


}
